package com.macro.mall.tiny.service.impl;

import com.macro.mall.tiny.service.RedisService;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author ：czx
 * @date ：Created in 2021/7/10 17:53
 * @descriptioin:Redis操作的实现类
 * @modified By：
 */
@Service
public class RedisServiceImpl implements RedisService {

    @Autowired
    private StringRedisTemplate   stringRedisTemplate;






    /**
     * description:
     *存储数据的
     */
    @Override
    public void set(String key, String value) {
            stringRedisTemplate.opsForValue().set(key,value);
    }
    /**
     * description:
     * 获取数据
     */
    @Override
    public String get(String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }
    /**
     * description:
     * 设置超时时间
     */
    @Override
    public boolean expire(String key, long expire) {
        return stringRedisTemplate.expire(key,expire, TimeUnit.SECONDS);
    }
    /**
     * description:
     * 删除数据
     */
    @Override
    public void remove(String key) {
        stringRedisTemplate.delete(key);

    }
    /**
     * description:
     * 自增操作
     * @param delta 自增
     *
     */
    @Override
    public Long increment(String key, long delta) {
        return stringRedisTemplate.opsForValue().increment(key,delta);
    }
}
